﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PacketPasser.commands
{
    public static class ProxyCommands
    {
        public static PacketProxy Restart(string input, PacketProxy currentProxy)
        {
            currentProxy.Stop();
            return currentProxy.CreateFresh();

        }

        public  static void IgnoreFirst(string input, PacketProxy proxy)
        {
            if (input.EndsWith("false"))
            {
                proxy.IgnoreFirst = false;
            }
            else if (input.EndsWith("true"))
            {
                proxy.IgnoreFirst = true;

            }
            Console.WriteLine("ignore first is:" + proxy.IgnoreFirst);
        }

        public static PacketProxy ChangeDestination(string input, PacketProxy proxy)
        {
            var args = input.After("destination ").Split(' ');

            if (args.Length < 1)
            {
                Console.WriteLine("could not process destination");
            }
            if (args.Length == 1)
            {
                var newDestination = args[0];
                    proxy.Stop();
                return new PacketProxy(proxy.ListenPort, newDestination, proxy.DestinationPort);
            }
            return null;
        }

        internal static void GetStatus(string input, PacketProxy proxy)
        {
            proxy.GetStatus();
        }
    }
}
